﻿/* QF classbuilder for Enlib */
using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Logging;

#region SYS_EmplDept实体类
public class SYS_EmplDept
{
	private string m_EmplID;
	private string m_DeptID;
	
	public SYS_EmplDept ()
	{
		m_EmplID="";
		m_DeptID="";
	}
	
	public string EmplID
	{
		get{return m_EmplID;}
		set{m_EmplID=value;}
	}
	public string DeptID
	{
		get{return m_DeptID;}
		set{m_DeptID=value;}
	}
}
#endregion

#region SYS_EmplDept管理类
public partial class LogicLayer
{
	public bool AddSYS_EmplDept(SYS_EmplDept theSYS_EmplDept)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "insert into SYS_EmplDept (EmplID,DeptID) values (@EmplID,@DeptID)";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_EmplDept.EmplID);
			db.AddInParameter(cmd, "@DeptID", DbType.String, theSYS_EmplDept.DeptID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("AddSYS_EmplDept:" + ex.Message );
			return false;
		}
	}
	
	public SYS_EmplDept GetSYS_EmplDeptFromDataReader(IDataReader dataReader)
	{
		try
		{
			SYS_EmplDept result = new SYS_EmplDept();
			
			if (dataReader["EmplID"] != null && dataReader["EmplID"] != System.DBNull.Value )
				result.EmplID = (string)dataReader["EmplID"];
			if (dataReader["DeptID"] != null && dataReader["DeptID"] != System.DBNull.Value )
				result.DeptID = (string)dataReader["DeptID"];
			
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetReaderSYS_EmplDept:" + ex.Message);
			return null;
		}
	}
	
	public SYS_EmplDept GetSYS_EmplDept(string EmplID,string DeptID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * From SYS_EmplDept where EmplID=@EmplID and DeptID=@DeptID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			db.AddInParameter(cmd, "@DeptID", DbType.String, DeptID);
			
			SYS_EmplDept result = null;
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				if (dataReader.Read())
				{
					result = GetSYS_EmplDeptFromDataReader( dataReader );
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("GetSYS_EmplDept:" + ex.Message);
			return null;
		}
	}
	
	public bool DelSYS_EmplDept(string EmplID,string DeptID)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "delete From SYS_EmplDept where EmplID=@EmplID and DeptID=@DeptID";
			
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			db.AddInParameter(cmd, "@EmplID", DbType.String, EmplID);
			db.AddInParameter(cmd, "@DeptID", DbType.String, DeptID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("DelSYS_EmplDept:" + ex.Message);
			return false;
		}
	}
	
	public bool UpdateSYS_EmplDept(SYS_EmplDept theSYS_EmplDept)
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "update SYS_EmplDept set  where EmplID=@EmplID and DeptID=@DeptID";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			db.AddInParameter(cmd, "@EmplID", DbType.String, theSYS_EmplDept.EmplID);
			db.AddInParameter(cmd, "@DeptID", DbType.String, theSYS_EmplDept.DeptID);
			
			db.ExecuteNonQuery(cmd);
			return true;
		}
		catch(Exception ex)
		{
			Logger.Write("UpdateSYS_EmplDept:" + ex.Message);
			return false;
		}
	}
	
	public List<SYS_EmplDept> ListSYS_EmplDept()
	{
		try
		{
			Database db = DatabaseFactory.CreateDatabase("connStr");
			string sql = "select * from SYS_EmplDept";
			System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql);
			
			 List<SYS_EmplDept> result = new  List<SYS_EmplDept>();
			using (IDataReader dataReader = db.ExecuteReader(cmd))
			{
				while (dataReader.Read())
				{
					SYS_EmplDept obj = GetSYS_EmplDeptFromDataReader( dataReader );
					if(obj != null)
						result.Add(obj);
				}
			}
			return result;
		}
		catch(Exception ex)
		{
			Logger.Write("ListSYS_EmplDept:" + ex.Message);
			return null;
		}
	}
	
}
#endregion